var userCtrl = $.mvc.controller.create('user', {
    views: {
        "garagesale_items_tpl": "views/garagesale_items.tpl",
        "item_detail_tpl": "views/item_detail.tpl"
    },
    /* Array of views to load */
    save: function() {
        value = $("#new-todo").val();
        $("#new-todo").val('');
        var that = this;
        var todo = new Todo();
        if(value.length == 0) return alert("Please enter some text");
        todo.text = value;

        todo.set({
            text: value
        });
        todo.save(function() {
            //var str = "<li><input id='"+todo.id+"' data-id='" + todo.id + "' class='check' type='checkbox' value='active' /><label for='"+todo.id+"'/><div class='todo-text' >" + todo.text + "</div> <span class='todo-destroy' style='display:none;'><input data-id='" + todo.id + "' type='button' class='handleArchive' value='archive' style='width: 90px;height: 43px;' /></span></li>";
            var str=$.template("list_item",{'entry':todo});
            $("#leftTodo ul").append($(str));
            that.updateCounters();
        });


    },
    /* This function updates the number of todos on the screen */
    updateCounters: function() {
        var el = $("#leftTodo");
        total = el.find("li").length;
        el.find(".count").html(total++);

        var el = $("#completedTodo");
        total = el.find("li").length;
        el.find(".count").html(total++);

        var el = $("#archivedTodo");
        total = el.find("li").length;
        el.find(".count").html(total++);
    },
    getItems: function(id) {
        $.ui.loadContent("#item_panel",false,false,"slide");
        $.get(BASE_URL+"garagesale_items?id="+encodeURIComponent(id),
            function(obj){
                obj=JSON.parse(obj);
                $("#itemList").html($.template('garagesale_items_tpl', {
                    sale_items: obj
                }));
            }
        );
        /*garagesale_item.fetchBy(id,function(result) {
            $("#itemList").html($.template('garagesale_items_tpl', {
                sale_items: result
            }));
        });*/
    },
    login: function(username, password) {
        
    },
    default:function() {
        /*garagesale_item.fetchAll(function(all) {
            $("#itemList").html($.template('garagesale_items_tpl', {
                items: all
            }));
        });*/

    },
    /* This is executed when the controller is created.  It assumes the views are loaded, but can not interact with models
     * This is useful for wiring up page events, etc.
     */
    init: function() {
        
    }
});